const fs = require('fs');
const path = require('path');
var tools = require('../../../libs/tools');
var config = require(tools.rootPath + 'config');
var { connection, pool, model } = require(tools.rootPath + 'libs/model');

var controller = require(tools.rootPath + 'libs/controller.js');

const { exec, execFile } = require('child_process');

module.exports = class extends controller {
    constructor() {
        super();
    }
    index(req, res) {
        //http://nodejs.cn/api/child_process.html#child_process_child_process_exec_command_options_callback
        execFile('node', [tools.rootPath + 'test.js'], (error, stdout, stderr) => {
            if (error) {
                console.error(`执行的错误: ${error}`);
                return;
            }
            console.log(`stdout: ${stdout}`);
            console.error(`stderr: ${stderr}`);
            console.log(JSON.parse(stdout));
        });


        res.send('ok');
    }
}